package windows.bet;

import java.util.Arrays;
import org.uqbar.arena.actions.MessageSend;
import org.uqbar.arena.layout.ColumnLayout;
import org.uqbar.arena.widgets.Button;
import org.uqbar.arena.widgets.Label;
import org.uqbar.arena.widgets.Panel;
import org.uqbar.arena.widgets.Selector;
import org.uqbar.arena.widgets.TextBox;
import org.uqbar.arena.widgets.TextFilter;
import org.uqbar.arena.widgets.TextInputEvent;
import org.uqbar.arena.windows.Dialog;
import org.uqbar.arena.windows.WindowOwner;
import com.uqbar.commons.StringUtils;
import domain.Bet;
import domain.ColumnBet;
import domain.extra.Column;

public class ColumnBetWindow extends Dialog<ColumnBet> {
	public ColumnBetWindow(WindowOwner parent) {
		super(parent, new ColumnBet());		
	}

	@Override
	protected void executeTask() {
		
	}

	@Override
	protected void addActions(Panel actions) {
		new Button(actions)
		.setCaption("accept")
		.onClick(new MessageSend(this, ACCEPT))
		.setAsDefault()
		.disableOnError(); 

		new Button(actions) 
		.setCaption("cancel")
		.onClick(new MessageSend(this, CANCEL));		
	}
	
	public void accept (){
		
		this.close(); 
		// cerrar la otra ventana. 
	}

	@Override
	protected void createFormPanel(Panel mainPanel) {
		Panel form = new Panel(mainPanel);
		form.setLayout(new ColumnLayout(2));

		Label betOnLabel = new Label(form);
		betOnLabel.setText("Bet on");
		Column[] element = Column.values();
		new Selector(form).setContents(Arrays.asList(element), "name")
		.bindValueToProperty("strategy");
	
		Label chipsLabel = new Label(form);
		chipsLabel.setText("Chips");
		TextBox chips = new TextBox(form);
		chips.bindValueToProperty(Bet.COUNT);
		
		TextFilter filter = new TextFilter(){

			public boolean accept(TextInputEvent event) {
				return StringUtils.isBlank(event.getInputText()) || StringUtils.isNumeric(event.getInputText());
			}
									
		}  ;
		chips.withFilter(filter);		
	}


	protected void createMainTemplate(Panel formBuilder) {
		this.setTitle(" Column Bet ");
		this.setTaskDescription(" Please, select a column");
		super.createMainTemplate(formBuilder);
	}
}
